/**
 * Created by leo on 2/2.
 */
angular.module('panels')
    .directive('panelItilMyOrdertodoAlarm', function (loadConf, $http, tabService) {
        return {
            scope: {},
            link: function (scope) {
                loadConf('panel-itil-my-ordertodo-alarm.yml').then(function (setting) {
                    scope.more = setting.more;
                    scope.types = setting.types;
                    scope.querytype = 1;
                    scope.changeType = function (index) {
                        scope.types.currentOn = index;
                        scope.querytype =index+1;
                        $http.jsonp(setting.listQueryUrl.replace('{QUERYTYPE}',scope.querytype), {
                            params: {
                                resType: scope.types[index].id.split(','),
                                t: new Date().getTime()
                            }
                        }).success(function (rows) {
                            scope.rows = rows.reList;
                            //scope.user_flag = rows.USER_FLAG;
                        });
                    };
                    scope.changeType(0);

                    // 打开综合视图
                    scope.openIntegrateView = function (flag,row) {
                    	var dept_id_1 = row.ISTAFFID_SUPPORT_DEPT_NAME;
                        //alert(" dept_id1 ="+dept_id);
                        dept_id = dept_id_1.substring(dept_id_1.length-5, dept_id_1.length) ;
                        // alert(" dept_id2 ="+dept_id);
                    	var search_dept_id =  "";
                    	
                    	if(dept_id=="监控维护室"){
                    		search_dept_id =  "100101";
                    	}else if(dept_id=="设备维护室"){
                    		search_dept_id =  "100102";
                    	} else if(dept_id=="需求分析室"){
                    		search_dept_id =  "100103";
                    	} else if(dept_id=="业务管理室"){
                    		search_dept_id =  "100104";
                    	} else if(dept_id=="综合质量室"){
                    		search_dept_id =  "100105";
                    	} else if(dept_id=="大数据室"){
                    		search_dept_id =  "100107";
                    	} else if(dept_id=="电子渠道室"){
                    		search_dept_id =  "100108";
                    	} else if(dept_id=="安全管理室"){
                    		search_dept_id =  "100109";
                    	}
                    	else
                    	{
                    		search_dept_id = dept_id_1;
                    	}
                        tabService.addTab({
                            name: row.ISTAFFID_SUPPORT_DEPT_NAME,
                            url: setting.integrateViewUrl.replace('{FLAG}', flag).replace('{DEPT_ID}', search_dept_id).replace('{QUERYTYPE}',scope.querytype)
                        });
                    };
                    // 打开本月工单情况视图
                    scope.openOverTimeByMonth = function (row) {
                    	var dept_id_1 = row.ISTAFFID_SUPPORT_DEPT_NAME;
	                   	var dept_id = dept_id_1.substring(dept_id_1.length-5, dept_id_1.length) ;
	                       // alert(" dept_id2 ="+dept_id);
	                   	var search_dept_id =  "";
	                   	
	                   	if(dept_id=="监控维护室"){
	                   		search_dept_id =  "100101";
	                   	}else if(dept_id=="设备维护室"){
	                   		search_dept_id =  "100102";
	                   	} else if(dept_id=="需求分析室"){
	                   		search_dept_id =  "100103";
	                   	} else if(dept_id=="业务管理室"){
	                   		search_dept_id =  "100104";
	                   	} else if(dept_id=="综合质量室"){
	                   		search_dept_id =  "100105";
	                   	} else if(dept_id=="大数据室"){
	                   		search_dept_id =  "100107";
	                   	} else if(dept_id=="电子渠道室"){
	                   		search_dept_id =  "100108";
	                   	} else if(dept_id=="安全管理室"){
	                   		search_dept_id =  "100109";
	                   	}else
	                   	{
	                   		search_dept_id = dept_id_1;
	                   	}
                        tabService.addTab({
                            name: row.ISTAFFID_SUPPORT_DEPT_NAME,
                            url: setting.overTimeByMonthUrl.replace('{DEPT_ID}', search_dept_id).replace('{QUERYTYPE}',scope.querytype)
                        });
                    };
                });
            },
            templateUrl: 'app/panel/itil/my-ordertodo-alarm.html'
        };
    });